package com.dreamtour.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dreamtour.DTO.ApplicationDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ApplicationMapper extends BaseMapper<ApplicationDTO> {
    @Select("""
        SELECT userId, '定制官' AS applyCategory, designerQualification AS qualification, applyingTime
        FROM servicedesigners
        WHERE qualifyStatus = 1
        UNION
        SELECT userId, '旅行社' AS applyCategory, agencyQualification AS qualification, applyingTime
        FROM agencies
        WHERE qualifyStatus = 1
    """)
    List<ApplicationDTO> getApplicationList();

    @Select("""
        SELECT userId, '定制官' AS applyCategory, designerQualification AS qualification, applyingTime
        FROM servicedesigners
        WHERE qualifyStatus = 1
    """)
    List<ApplicationDTO> getDesignerApplicationList();

    @Select("""
        SELECT userId, '旅行社' AS applyCategory, agencyQualification AS qualification, applyingTime
        FROM agencies
        WHERE qualifyStatus = 1
    """)
    List<ApplicationDTO> getAgencyApplicationList();

    @Select("""
        SELECT userId, '定制官' AS applyCategory, designerQualification AS qualification, applyingTime
        FROM servicedesigners
        WHERE qualifyStatus = 1 and userId = #{userId}
        UNION
        SELECT userId, '旅行社' AS applyCategory, agencyQualification AS qualification, applyingTime
        FROM agencies
        WHERE qualifyStatus = 1 and userId = #{userId}
    """)
    List<ApplicationDTO> selectById(Integer userId);
}

